
class AuthTagState{
    authTag:number = 0;
    readonly:boolean = true;
    writeable:boolean = false;
}

class AuthTagClass{
    readonly None = 0;
    readonly Read = 1;
    readonly Write = 2;
    readonly Add = 4;
    readonly Delete = 8;
    readonly Lock = 128;
    readonly Archive = 256;
    readonly All = this.Read | this.Write | this.Lock | this.Archive;
    readonly(authTag:number|undefined){
        return !this.writable(authTag)
    }
    /** 只有明确授权可写权限，才返回true。(不包括锁定和归档权限)  */
    writable(authTag:number|undefined){

        if(authTag){
            return (authTag & this.Write) == this.Write || (authTag & this.Lock) == this.Lock || (authTag & this.Archive) == this.Archive;
        }else{
            return false;
        }
    }
    /** 根据authTag判断是否可锁定,只有明确授权为Lock，才返回true */
    lockable(authTag:number|undefined){
       if(authTag){
           return (authTag & this.Lock) == this.Lock;
       }else{
           return false;
       }
    }
    /** 根据authTag判断是否可归档 */
    archivable(authTag:number|undefined){
        if(authTag){
            return (authTag & this.Archive) == this.Archive;
        }else{
            return false;
        }
    }
    buildAuthTagState(authTag:number){
        let state = new AuthTagState();
        state.authTag = authTag;
        state.writeable = (authTag & this.Write) == this.Write; //只有明确授权可写权限，才可写
        state.readonly = !state.writeable;//其他授权都是只读
        return state;
    }
}
let AuthTag : AuthTagClass = new AuthTagClass();


export {AuthTag, AuthTagState}